Attribute VB_Name = "modClientTCP"
Option Explicit

'send data
Public Sub SendData(ByVal data As String)
    Call frmMainMenu.Socket.SendData(data)
End Sub

'Register new user
Public Sub CMD_CreateNewUser(ByVal username As String, ByVal password As String, ByVal IP As String, ByVal Sec_Word As String)
    Call SendData("createuser" & SEP_CHAR & username & SEP_CHAR & password & SEP_CHAR & IP & SEP_CHAR & Sec_Word)
End Sub

'Login User
Public Sub CMD_LoginUser(ByVal username As String, ByVal password As String, ByVal Sec_Word As String)
    Call SendData("loginuser" & SEP_CHAR & username & SEP_CHAR & password & SEP_CHAR & Sec_Word)
End Sub

'Logs out
Public Sub CMD_LogOutUser(ByVal username As String)
    Call SendData("logoutuser" & SEP_CHAR & username)
End Sub

'Connects To Server
Public Sub ConnectToServer()
    ServerIP = ReadINI("CONNECTION", "SERVERIP", App.Path & "\config.ini")
    ServerPort = ReadINI("CONNECTION", "SERVERPORT", App.Path & "\config.ini")
    If Not IsConnected Then
        frmMainMenu.Socket.Close
        frmMainMenu.Socket.RemoteHost = ServerIP
        frmMainMenu.Socket.RemotePort = ServerPort
        frmMainMenu.Socket.Connect
    End If
End Sub

'Check if socket is connected to gameserver
Public Function IsConnected() As Boolean
    If frmMainMenu.Socket.State = sckConnected Then
        IsConnected = True
    Else
        IsConnected = False
    End If
End Function

'Check if logged in
Public Function isLoggedIn() As Boolean
    If NameOfUser <> vbNullString Then
        isLoggedIn = True
    Else
        isLoggedIn = False
    End If
End Function

'Check if socket is connecting to gameserver
Public Function IsConnecting() As Boolean
    If frmMainMenu.Socket.State = sckConnecting Then
        IsConnecting = True
    Else
        IsConnecting = False
    End If
End Function
